﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IBLL;

namespace MisCLL
{
    public class DAOFactory
    {
        private volatile static DAOFactory _instance = null;
        private static readonly object lockHelper = new object();

        private string ip;
        private string port;

        private DAOFactory()
        {
            //读取配置信息
            this.ip = System.Configuration.ConfigurationManager.AppSettings["ServerAddr"];
            this.port = System.Configuration.ConfigurationManager.AppSettings["ServerPort"];
        }

        public static DAOFactory CreateInstance()
        {
            if (_instance == null)
            {
                lock (lockHelper)
                {
                    if (_instance == null)
                        _instance = new DAOFactory();
                }
            }
            return _instance;
        }

        //获取操作机配置表远程服务对象
        public IPos GetRemotePos()
        {
            return (IPos)Activator.GetObject(typeof(IBLL.IPos), string.Format("tcp://{0}:{1}/PosDAO", this.ip, this.port));
        }

        //获取操作用户配置表远程服务对象
        public IOper GetRemoteOper()
        {
            return (IOper)Activator.GetObject(typeof(IBLL.IOper), string.Format("tcp://{0}:{1}/OperDAO", this.ip, this.port));
        }

        //获取统计类型配置表远程服务对象
        public IType GetRemoteType()
        {
            return (IType)Activator.GetObject(typeof(IBLL.IType), string.Format("tcp://{0}:{1}/TypeDAO", this.ip, this.port));
        }

        //获取部门信息配置表远程服务对象
        public IDepart GetRemoteDepart()
        {
            return (IDepart)Activator.GetObject(typeof(IBLL.IDepart), string.Format("tcp://{0}:{1}/DepartDAO", this.ip, this.port));
        }

        //获取库位信息配置表远程服务对象
        public IArea GetRemoteArea()
        {
            return (IArea)Activator.GetObject(typeof(IBLL.IArea), string.Format("tcp://{0}:{1}/AreaDAO", this.ip, this.port));
        }

        //获取查询支付工具配置表远程服务对象
        public ICard GetRemoteCard()
        {
            return (ICard)Activator.GetObject(typeof(IBLL.ICard), string.Format("tcp://{0}:{1}/CardDAO", this.ip, this.port));
        }

        //获取客户分店代码配置表远程服务对象
        public ICusShop GetRemoteCusShop()
        {
            return (ICusShop)Activator.GetObject(typeof(IBLL.ICusShop), string.Format("tcp://{0}:{1}/CusShopDAO", this.ip, this.port));
        }

        //获取客户结算周期配置表远程服务对象
        public IDayJS GetRemoteDayJS()
        {
            return (IDayJS)Activator.GetObject(typeof(IBLL.IDayJS), string.Format("tcp://{0}:{1}/DayJSDAO", this.ip, this.port));
        }

        //获取供应商类型配置表远程服务对象
        public IJhType GetRemoteJhType()
        {
            return (IJhType)Activator.GetObject(typeof(IBLL.IJhType), string.Format("tcp://{0}:{1}/JhTypeDAO", this.ip, this.port));
        }

        //获取客户结算类型配置表远程服务对象
        public IFkType GetRemoteFkType()
        {
            return (IFkType)Activator.GetObject(typeof(IBLL.IFkType), string.Format("tcp://{0}:{1}/FkTypeDAO", this.ip, this.port));
        }

        //获取包装单位配置表远程服务对象
        public IUnit GetRemoteUnit()
        {
            return (IUnit)Activator.GetObject(typeof(IBLL.IUnit), string.Format("tcp://{0}:{1}/UnitDAO", this.ip, this.port));
        }

        //获取钱款用途配置表远程服务对象
        public IYT GetRemoteYT()
        {
            return (IYT)Activator.GetObject(typeof(IBLL.IYT), string.Format("tcp://{0}:{1}/YTDAO", this.ip, this.port));
        }

        //获取客户部门代码配置表远程服务对象
        public ICusDep GetRemoteCusDep()
        {
            return (ICusDep)Activator.GetObject(typeof(IBLL.ICusDep), string.Format("tcp://{0}:{1}/CusDepDAO", this.ip, this.port));
        }

        //获取供应商配置表远程服务对象
        public ISupply GetRemoteSupply()
        {
            return (ISupply)Activator.GetObject(typeof(IBLL.ISupply), string.Format("tcp://{0}:{1}/SupplyDAO", this.ip, this.port));
        }

        //获取商品代码表远程服务对象
        public IGoods GetRemoteGoods()
        {
            return (IGoods)Activator.GetObject(typeof(IBLL.IGoods), string.Format("tcp://{0}:{1}/GoodsDAO", this.ip, this.port));
        }

        //获取系统配置表远程服务对象
        public ISys0 GetRemoteSys0()
        {
            return (ISys0)Activator.GetObject(typeof(IBLL.ISys0), string.Format("tcp://{0}:{1}/Sys0DAO", this.ip, this.port));
        }

        //获取进货入库表远程服务对象
        public IBacf GetRemoteBacf()
        {
            return (IBacf)Activator.GetObject(typeof(IBLL.IBacf), string.Format("tcp://{0}:{1}/BacfDAO", this.ip, this.port));
        }

        //获取退货出库表远程服务对象
        public IRacf GetRemoteRacf()
        {
            return (IRacf)Activator.GetObject(typeof(IBLL.IRacf), string.Format("tcp://{0}:{1}/RacfDAO", this.ip, this.port));
        }

        //获取仓库表远程服务对象
        public IShop GetRemoteShop()
        {
            return (IShop)Activator.GetObject(typeof(IBLL.IShop), string.Format("tcp://{0}:{1}/ShopDAO", this.ip, this.port));
        }

        //获取客户表远程服务对象
        public ICustomer GetRemoteCustomer()
        {
            return (ICustomer)Activator.GetObject(typeof(IBLL.ICustomer), string.Format("tcp://{0}:{1}/CustomerDAO", this.ip, this.port));
        }

        //获取客户商品表远程服务对象
        public IGoodsCus GetRemoteGoodsCus()
        {
            return (IGoodsCus)Activator.GetObject(typeof(IBLL.IGoodsCus), string.Format("tcp://{0}:{1}/GoodsCusDAO", this.ip, this.port));
        }

        //获取批发销售表远程服务对象
        public ISacf GetRemoteSacf()
        {
            return (ISacf)Activator.GetObject(typeof(IBLL.ISacf), string.Format("tcp://{0}:{1}/SacfDAO", this.ip, this.port));
        }
    }
}
